#include <stdio.h>

void getnchar(char *str, int n)
{
    while (n > 0 && (*str = getchar()) != '\n')
        n--, str++;
    *str = '\0';
}

int my_strlen(char *str)
{
    char *p = str;
    while (*p)
        p++;
    return p - str;
}

int my_strncat(char *dest, char *src, int n)
{
    while (*dest)
        dest++;
    int m = n;
    while (m > 0 && *src)
        m--, *dest++ = *src++;
    *dest = '\0';
    return n - m;
}

int my_strspn(char *str, char *keys)
{
    int appear[256] = {0};
    while (*keys)
        appear[(int)*keys] = 1, keys++;
    char *p = str;
    while (*p && appear[(int)*p] == 1)
        p++;
    return p - str;
}

int main()
{
    int nCase;
    scanf("%d\n", &nCase); /* 吃掉行末的回车，否则getnchar会遇到回车返回 */
    while (nCase--)
    {
        char a[1000], b[1000], c[1000];
        getnchar(a, 1000);
        getnchar(b, 1000);
        getnchar(c, 1000);

        int n;
        scanf("%d\n", &n); /* 为下一轮吃掉行末的回车 */

        printf("%d\n", my_strlen(a));
        printf("%d %s\n", my_strncat(a, b, n), a);
        printf("%d\n", my_strspn(b, c));
    }
    return 0;
}
